<?php
Globals::requireController('Admin');

class UploadController extends AdminController
{
	public function __construct($config = null)
	{
		parent::__construct($config);
		$this->config['layoutEnabled'] 	= false;
		$this->config['viewEnabled'] 	= false;
	}
	
	public function indexAction()
	{
		$name	= $this->getParam('name');
		
		Globals::requireClass('UploadFile');
		$upload = new UploadFile();
		$upload->allowExts = array("jpg" , "png" , "gif" , "jpeg" , "JPG" , "PNG" , "GIF" , "JPEG");
		$upDir = "../upload/";
		$monDir = $upDir.date("Ym");
		if(!is_dir($monDir)){
			mkdir($monDir , 0777);
		}
		$dayDir = $monDir."/".date("d");
		if(!is_dir($dayDir)){
			mkdir($dayDir , 0777);
		}
		$upload->savePath = $dayDir."/";
		
		$thumbMaxWidth 	= 150;
		$thumbMaxHeight = 150;
		if ($name)
		{
			switch ($name)
			{
				case 'gallery':
					$thumbMaxWidth 	= 112;
					$thumbMaxHeight = 112;
					break;
				default:
					$thumbMaxWidth 	= 112;
					$thumbMaxHeight = 112;
					break;
			}
		}	
		//生成缩略图
		$upload->thumb = false;
		$upload->thumbMaxHeight = $thumbMaxHeight;
		$upload->thumbMaxWidth = $thumbMaxWidth;
		$upload->thumbSuffix = '_240';
			
		if ($upload->upload()){
			$fileInfo = $upload->getUploadFileInfo();
			$form['pic'] = $fileInfo[0]['savepath'].$fileInfo[0]['savename'];
			$picArr = explode("." , $fileInfo[0]['savename']);
			$form['picthumb'] = $fileInfo[0]['savepath'].$picArr[0]."_240".".".strtolower($picArr[1]);
			$msg	= $form['pic'].";;".$form['picthumb'];
		}else {
			$msg = "0;;".$upload->getErrorMsg();
		}
		echo $msg;
	}
}